local ClientOHOH =_G.ClientOHOH
local M = {}
local shopPanel = nil
local CallBackManager = ClientOHOH.load.CallBackManager()
local LanguageHelper=_G.LanguageHelper 
local listUiData = {}

function Initsts()
    local ui = {
        list={},
        gSideTag = "ctrl.SideBar.gamePass.btn",
        gSizeTagPos = "ctrl.SideBar.gamePass.position",
    }

    local listName = {
        "VIP",
        "doubleDiamond",
        "doubleRoll",
        "luckRoll",
        "quickRollSpeed",
        "shinyHunter",
        "superLuckyRoll",
    }
    for _, value in pairs(listName) do
        ui.list[value] = {
            buyBtn = "ctrl.gamePasses."..value..".btn",
            price = "ctrl.gamePasses."..value..".price"
        }
    end
    return ui
end

function M.GetInitUiList()
    return Initsts()
end

function M.Init(ShopPanel)
    shopPanel = ShopPanel
    CallBackManager:AddRbxConnect(shopPanel,shopPanel.insts.gamepass.gSideTag.Activated,function()
        shopPanel:ScrollingGo(shopPanel.insts.gamepass.gSizeTagPos)
    end)
end

--更新gamepass状态
function M.UpdateGamePass(gamePassData)
    for _,v in pairs(listUiData) do
        v:update(gamePassData)
    end
end


function M.Full(data)
    for _, value in pairs(data) do
        M.FullGamePassList(value)
    end
end

--填充gamepass的list
function M.FullGamePassList(data)
    local gamepassUi = shopPanel.insts.gamepass
    if data.isHad then
        gamepassUi.list[data.item_id].price.Text = LanguageHelper:GetText(20608)
    else
        gamepassUi.list[data.item_id].price.Text =data.price
        CallBackManager:AddRbxConnect(shopPanel,gamepassUi.list[data.item_id].buyBtn.Activated,function()
            shopPanel.ShopBuyEvent:Action(data.buyInfo)
        end)
    end
    table.insert(listUiData,{
        ui=gamepassUi.list[data.item_id],
        cfg=data,
        update=function(this,data)
            if data[this.cfg.name] then
                this.cfg.isHad = true
            end
            if this.cfg.isHad then
                this.ui.price.Text=LanguageHelper:GetText(20608)
            end
        end
    })
end

function M.Get()
    return M
end

return M 